<?php

namespace App\Observers;

use App\Models\Health;
use App\servers\EsServer;

class EsObserver
{
    /**
     * Handle the Health "created" event.
     *
     * @param  \App\Models\Health  $health
     * @return void
     */
    public function created(Health $health)
    {
        $id = $health['id'];
        $health = $health->toArray();
        $index_name = '2008a_yl';
        EsServer::Entrance()->add_doc($id,$health,$index_name); //创建索引同步Es
    }

    /**
     * Handle the Health "updated" event.
     *
     * @param  \App\Models\Health  $health
     * @return void
     */
    public function updated(Health $health)
    {
//        $id = $health['id'];
//        $index_name = '2008a_yl';
//        EsServer::Entrance()->add_doc($id,$health,$index_name);
    }

    /**
     * Handle the Health "deleted" event.
     *
     * @param  \App\Models\Health  $health
     * @return void
     */
    public function deleted(Health $health)
    {
        //
    }

    /**
     * Handle the Health "restored" event.
     *
     * @param  \App\Models\Health  $health
     * @return void
     */
    public function restored(Health $health)
    {
        //
    }

    /**
     * Handle the Health "force deleted" event.
     *
     * @param  \App\Models\Health  $health
     * @return void
     */
    public function forceDeleted(Health $health)
    {
        //
    }
}
